package com.buddies.lottery.ui.lottery.detail;

import android.view.View;
import android.widget.TextView;

import com.buddies.lottery.R;
import com.buddies.lottery.data.bean.LotteryTab;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

public class LotteryTabAdapter extends BaseQuickAdapter<LotteryTab, BaseViewHolder> {

    private int mSelectedItem = 0;

    public LotteryTabAdapter(List<LotteryTab> tabs) {
        super(R.layout.item_lottery_tab, tabs);
    }

    @Override
    protected void convert(BaseViewHolder helper, LotteryTab item) {
        helper.itemView.setSelected(helper.getLayoutPosition() == mSelectedItem);
        ((TextView) helper.getView(R.id.tab_name)).setText(item.name);
    }

    @Override
    public void setOnItemClick(View v, int position) {
        super.setOnItemClick(v, position);
        mSelectedItem = position;
        notifyDataSetChanged();
    }

    public int getSelectedItem() {
        return mSelectedItem;
    }

    public int getSelectedItemId() {
        return getItem(mSelectedItem).id;
    }

}
